Mac OS Sound

| Previous | Chapter Contents | Chapter Top | Next |

Sound Commands

New sound commands have been added since the release of Sound Manager 3.0. You can use these sound commands with the SndDoImmediate and SndDoCommand functions.

clockComponentCmd

This command turns the sound clock on or off. Use this command to turn on the sound clock before attempting to use the getClockComponentCmd . Set the value of param1 in this command to be true or false , where true turns on the clock.

SndCommand     cmd;

cmd.cmd = clockComponentCmd;
cmd.param1 = true; // turn the clock on
err = SndDoImmediate(chan, &clockComponentCmd);

getClockComponentCmd

This command returns the the sound clock component instance. Set the value of param2 to be a pointer to a ComponentInstance .

SndCommand          cmd;
ComponentInstance clock;

cmd.cmd = getClockComponentCmd;
cmd.param2 = (long)&clock; // get the clock component
err = SndDoImmediate (chan, &getClockComponentCmd);

scheduledSoundCmd

Use this command with the new ScheduledSoundHeader structure. It is similar to the bufferCmd in that param2 contains a pointer to this structure. This command can be used to schedule a sound and/or to install a callBackCmd with this one command. The first field of this structure is a union of one of the three existing SoundHeader types, as used in the bufferCmd . The flags field is used to specify if there is a valid TimeRecord and/or parameters for the CallBackProc .

/* ScheduledSoundHeader flags*/
enum {
    kScheduledSoundDoScheduled = 1 << 0,
    kScheduledSoundDoCallBack = 1 << 1
};

struct ScheduledSoundHeader {
    SoundHeaderUnion u;
    long        flags;
    short       reserved;
    short       callBackParam1;
    long        callBackParam2;
    TimeRecord  startTime;
};

linkSoundComponentsCmd

Use this command to configure the given sound channel's components to support your sound format. By default, a channel will be configured to play 8 bit non-compressed samples. If you wanted to play 16 bit or compressed audio, then you had to start your sound at non-interrupt time so that the proper sound components would be opened and installed. By using this new command you can point to a SoundComponentData structure in param2 , and the proper set of sound components will be configured into your channel. At this point you can start a sound playing at interrupt time.

rateMultiplierCmd

The rateMultiplierCmd uses a fixed-point value to provide a multiplier to the playback rate of all sounds played on this channel. This allows you to vary the sample rate of the sound being played, and thus control its pitch. The getRateMultiplierCmd returns the current rate multiplier. For example, to play all sounds on a channel shifted up one octave in pitch, you could use the following code:

                    OSErr RaisePitchOneOctave(SndChannelPtr chan)
                    {
                            SndCommand cmd;
                            OSErr err;

                            cmd.cmd = rateMultiplierCmd;
                            cmd.param1 = 0;
                            cmd.param2 = 0x00020000; // rate of 2.0

                            err = SndDoImmediate(chan, &cmd);
                            return (err);
                    }
The rateMultiplierCmd is more useful than previous versions of rateCmd , which applied only to the sound currently playing and was based on the sampling rate of the hardware.


© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |